/**
 * @file remote.js
 * @author admin
 * @description 异地速约
 */
var app = getApp();
var util = require('../../utils/util.js');
Page({
  data:{
    qualificationIndex: ['0', '0'],//索引
     qualificationArray: [
       ['田林路', '宜山路', '桂林路','陆家嘴', '吴中路','天府三街'],
       ['1-503','1-503']
     ], //付款类型数组
     objectQualificationArray: [{//第二级
         "No": "1",
         "parid": "1",//表示第一级里的第一个
         "regname": "1-503"
       },
       {
         "No": "2",
         "parid": "1",
         "regname": "1-305"
       },
         {
         "No": "3",
         "parid": "2",//表示第一级里的第二个
         "regname": "715"
       }
     ],
     qualificationType: "", //	*供应商要求资质类型 0 品牌/代理授权书 1 经营许可证 2 软件代理资质 3 无
     qualificationName: "",//第一级名称
     categoryBrandType: "", //	*供应商要求品牌品类类型 0 同品牌 1 同品类品牌
     categoryBrandName: "",//第二级名称
     currentTitle:"",
     sdate:"",
     stime:"",
     etime:""
 },
 bindQualificationChange: function (e) {//供应商要求
     let vm = this;
     vm.setData({
       "qualificationIndex[0]": e.detail.value[0],
       "qualificationIndex[1]": e.detail.value[1],
       "qualificationName": vm.data.qualificationArray[0][e.detail.value[0]],
       "categoryBrandName": vm.data.qualificationArray[1][e.detail.value[1]] || "",
       "qualificationType": e.detail.value[0], //	资质类型 
       "categoryBrandType": e.detail.value[1] || "", //	品牌品类类型
     })
   },
   bindQualificationColumnChange: function(e) {//供应商要求
     let vm = this;
     // console.log('修改的列为', e.detail.column, '，值为', e.detail.value, vm.data.objectQualificationArray);
     switch (e.detail.column) {
       case 0:
         let list = [];
         // 此循环是进行第二级分组赋值
         for (var i = 0; i < vm.data.objectQualificationArray.length; i++) {
           if (e.detail.value + 1 == vm.data.objectQualificationArray[i].parid) {
             list.push(vm.data.objectQualificationArray[i].regname)
           }
         }
         vm.setData({
           "qualificationArray[1]": list,
           "qualificationIndex[0]": e.detail.value,
           "qualificationIndex[1]": 0
         })
  
     }
   },
  onLoad () {
    this.setData({
      sdate: util.getDate(),
      stime: util.getTime(),
      etime: util.getTime(1)
    });
    app.updateCheckList([]);
    app.updateCheckBrList([]);
    app.updateContactsList([]);
    app.updateBoardroomList([]);
  },
  onShow () {
    this.setData({
      rcontacts: app.globalData.checkList,
      rboardroom: app.globalData.checkBrList
    });
  },
  onHide () {
    app.updateCheckList(this.data.rcontacts);
  },
  onReady () {
  },
  inputTitle (e) {
    this.setData({
      currentTitle: e.detail.value
    });
  },
  onChangeSdate (e) {
    var now = new Date();
    if(now < e.detail.value){
      wx.showToast({
        title: '只能预订今天之后的日期',
        image: '../../images/failmsg.png',
        duration: 2000
      });
      return;
    }
    this.setData({
      sdate: e.detail.value,
    });
  },
  onChangeStime (e) {
    this.setData({
      stime: e.detail.value,
      etime: e.detail.value
    });
  },
  onChangeEtime (e) {
    if(this.data.stime <= this.data.etime) {
      wx.showToast({
        title: '当前会议时间无效',
        image: '../../images/failmsg.png',
        duration: 2000
      });
      return;
    }
    this.setData({
      etime: e.detail.value
    });
  },
  onSelect () {
    wx.navigateTo({
      url: "../contacts/contacts?type=remote"
    })
  },
  //点击预定
  //先查询当前地点当前时间是否有人预定
  onSearch () {
    wx.request({
      url: app.globalData.domain + '/meetingRecord/makeMeeting', //仅为示例，并非真实的接口地址
      data: {
        openid: wx.getStorageSync('userInfo').openid,
        qualificationIndex: this.data.qualificationIndex,
        qualificationType: this.data.qualificationType,
        qualificationName: this.data.qualificationName,
        categoryBrandType: this.data.categoryBrandType,
        categoryBrandName: this.data.categoryBrandName,
        date: this.data.sdate,
        startTime: this.data.stime,
        endTime: this.data.etime,
        title: this.data.currentTitle
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success (res) {
        var data = res.data;
        console.log(data);
        wx.showToast({
          title: data.msg,
          icon: 'none',    //如果要纯文本，不要icon，将值设为'none'
          duration: 2000     
        }) 
        if(data.code == 200) {
          wx.switchTab({
            url: '../user/user'
          })
        }
      },
      error (res) {
        wx.showToast({
          title: '服务调用失败',
          icon: 'none',    //如果要纯文本，不要icon，将值设为'none'
          duration: 1000     
        }) 
      }
    })
    // var params =  "attendees="+ attendees + '&' + 
    //               "cities="+ cities + '&' + 
    //               "device="+ this.data.currentDev + '&' + 
    //               "startDate="+ this.data.sdate + '&' + 
    //               "endDate="+ this.data.edate + '&' + 
    //               "startTime=" + this.data.stime + '&' + 
    //               "endTime=" + this.data.etime + '&' +  
    //               "duration=" + duration;
    // var url = "../remoteResult/remoteResult?"+params;
    // wx.navigateTo({
    //   url: url
    // });
  }
})
